package com.hzhc.filter;

import com.hzhc.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName: WebMvcConfig
 * @Description:拦截器配置
 * @version 1.0
 * @author: duanhm
 * @Date: 2022/01/29 22:07:34
 *
 */

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {


	@Bean
	public TokenInterceptor tokenInterceptor() {
		return new TokenInterceptor();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 注册登录拦截器
		registry.addInterceptor(tokenInterceptor())
				.addPathPatterns("/**")
				.excludePathPatterns("/ssoIndex")
				.excludePathPatterns("/static/**")
				.excludePathPatterns("/login")
				.excludePathPatterns("/cntrImg/**")
				.excludePathPatterns("/yworderFile/**")
				.excludePathPatterns("/captcha/**")
				.excludePathPatterns("/sydImageFile/**")
				.excludePathPatterns("/zcFile/**")
				.excludePathPatterns("/companyInfo/getCarTeamById")
				.excludePathPatterns("/app/saveDriverMember") // 司机手机扫描加入车队保存
				.excludePathPatterns("/auth/refreshToken")// 刷新token
		        .excludePathPatterns("/base/json/getCarTeamById") // 司机手机扫描加入车队

				.excludePathPatterns("/base/json/saveDriverMember"); // 司机手机扫描加入车队保存

	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**")
				.addResourceLocations("classpath:/static/");

	}
}
